﻿@using Masuit.MyBlogs.Core.Models.Entity
@model IList<Masuit.MyBlogs.Core.Models.DTO.NoticeDto>
@{
    ViewBag.Title = "网站公告栏";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container min-height610">
    <ol class="cd-breadcrumb triangle">
        <li><a asp-controller="Home" asp-action="Index">首页</a></li>
        <li class="current"><em>@ViewBag.Title</em></li>
    </ol>
    <a asp-controller="Dashboard" asp-action="Index" asp-fragment="/notice/index" class="btn btn-info">发布新公告</a>
    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
        @foreach (var n in Model)
        {
            <div class="panel panel-default">
                <div class="panel-heading" role="tab" id="heading-@n.Id">
                    <h4 class="panel-title">
                        <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-@n.Id" aria-expanded="false" aria-controls="collapse-@n.Id">
                            @n.ModifyDate.ToString("yyyy-MM-dd") @n.Title
                        </a>
                    </h4>
                </div>
                <div id="collapse-@n.Id" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-@n.Id">
                    <div class="panel-body">
                        <div class="btn-group">
                            <a class="btn btn-info" onclick="del(@n.Id,'@n.Title')">删除</a>
                            <a class="btn btn-danger" asp-controller="Dashboard" asp-action="Index" asp-fragment="/notice/index?id=@n.Id" target="_blank">修改</a>
                        </div>
                        @Html.Raw(n.Content)
                    </div>
                </div>
            </div>
        }
    </div>
    @{
        await Html.RenderPartialAsync("_Pagination", ViewData["page"]);
        await Html.RenderPartialAsync("_ArticleListAdvertisement", (Advertisement)ViewBag.Ads);
    }
</div>
<script>
    function del(id, title) {
        swal({
            title: "确认删除这条公告吗？",
            text: title,
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            showLoaderOnConfirm: true,
            animation: true,
            allowOutsideClick: false
        }).then(function () {
            $.post("/notice/delete", {
                id: id
            }, function (data) {
                window.notie.alert({
                    type: 1,
                    text: data.Message,
                    time: 4
                });
                window.location.reload();
            });
        }, function () {
        });
    }
</script>